package com.sjl.db137.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sjl.db137.config.R;
import com.sjl.db137.entity.Rolemenu;
import com.sjl.db137.service.RolemenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author sjl
 * @date 2024/12/31 10:09
 * @Description
 */
@RestController
@CrossOrigin(origins = "*")
public class RolemenuController {

    @Autowired
    private RolemenuService rolemenuService;

    @GetMapping("selectrolemenu")
    public R selectrolemenu() {
        List<Rolemenu> rolemenuList = this.rolemenuService.list();

        return new R().add("rolemenuList", rolemenuList);
    }

    @GetMapping("selectRoleMenuById/{roleid}")
    public R selectRoleMenuById(@PathVariable("roleid") int roleid) {
        QueryWrapper<Rolemenu> rolemenuQueryWrapper = new QueryWrapper<>();
        rolemenuQueryWrapper.eq("roleid", roleid);
        List<Rolemenu> rolemenuList = this.rolemenuService.list(rolemenuQueryWrapper);
        return new R().add("rolemenuList", rolemenuList);
    }

    /***
     * 根据角色id修改角色对应的菜单id集合
     * @return
     */
    @PostMapping("updateRoleMenuId")
    public R updateRoleMenuId(@RequestBody Map<String,Object> map){
        int roleid=Integer.parseInt(map.get("roleid")+"");
        List<Integer> listMenu =(List<Integer>) map.get("listMenu");
        boolean boo= this.rolemenuService.updateRoleMenuId(roleid,listMenu);
        return new R().add("boo",boo);
    }

}
